section .data
	ONE  dw 1
	N1  equ 1
	LerInteiroMsg db "INPUT:"
	LIMSGSIZE EQU $-LerInteiroMsg
	outputstring db "OUTPUT:"
	EISIZE EQU $-outputstring
section .bss
	AUX  resw  1
	N  resw  1
	charLido resb 1
	stringToWrite resb 12
section .text
	global _start
_start: 
	push AX
	call LerInteiro
	pop word [N]
	mov AX,[N]
%if N1 = 1
	push word [ONE]
	call EscreverInteiro
%endif
FAT:	sub AX,[ONE]
	cmp Ax,0
	je FIM
	mov [AUX],AX
	imul AX,[N]
	mov [N],AX
	mov AX,[AUX]
	jmp FAT
FIM:	push word [N]
	call EscreverInteiro
	mov EAX,1
	mov EBX,0
	int 0x80
LerInteiro: push EAX
			push EBX
			push ECX
			push EDX
			mov EAX,4
			mov EBX,1
			mov ECX,LerInteiroMsg
			mov EDX,LIMSGSIZE
			int 80h
			mov EAX,0
readLoop:	push EAX
			mov EAX,3
			mov EBX,0
			mov ECX,charLido
			mov EDX,1
			int 80h
			pop EAX
			cmp byte [charLido],0x0a
			je endLerInteiro
			mov EBX,0
			mov BL,[charLido]
			sub BL,0x30
			imul AX,10
			add AX,BX
			jmp readLoop
endLerInteiro:
			pop EDX
			pop ECX
			pop EBX
			mov [ESP + 8],AX
			pop EAX
			ret
EscreverInteiro: push EBP
			mov EBP,ESP
			push EAX
			push EBX
			push ECX
			push EDX
			mov EAX,4
			mov EBX,1
			mov ECX,outputstring
			mov EDX,EISIZE
			int 80h
			mov ECX,0
			mov EAX,0
			mov AX,word [EBP + 8]
			mov EBX,10
divloop:	mov EDX,0
			div EBX
			ADD DL,0x30
			push DX
			inc CX
			cmp AX,0
			jne divloop
			mov EBX,0
nextdigit:	pop AX
			mov [stringToWrite + EBX],AL
			inc BX
			loop nextdigit
			mov byte [stringToWrite + EBX],0x0d
			inc BX
			mov byte [stringToWrite + EBX],0x0a
			mov EAX,4
			mov EDX,12
			mov EBX,1
			mov ECX,stringToWrite
			int 80h
			pop EDX
			pop ECX
			pop EBX
			pop EAX
			pop EBP
			ret 2
